
use "$root/data/cleaned/bg_created", replace

bysort narrow_employer year: gen first_obs_in_year=_n==1
egen num_narrow_employer_obs=sum(first_obs_in_year),by(narrow_employer)

gen any_tech2= year>=yofl_tech &yofl_tech!=.

gen years_until_tech=yofl_tech-year

forvalues i=9(-1)1{
	gen M_`i'=years_until_tech==`i'
}
forvalues i=0(1)9{
	gen P_`i'=years_until_tech==-`i'
}
replace M_1=0

gen routine= basic_aa==1| clerk==1| mail==1| routine_accounting==1| light_physical==1
gen functional=light_physical==1| legal==1| accounting_finance==1| sales_cust==1| marketing==1| logistics==1| hr==1
gen high_sk_tasks= research==1| higher_level_mgmt==1| other_cognitive==1| writing==1 

gen routine_num= basic_aa+ clerk+ mail+ routine_accounting+ light_physical
gen functional_num=light_physical+ legal+ accounting_finance+ sales_cust+ marketing+ logistics+ hr
gen high_sk_tasks_num= research+ higher_level_mgmt+ other_cognitive+ writing 

preserve 

keep if year==yofl_tech +1

collapse (max) any_tech_ya= any_tech, by(narrow_employer )
tempfile file1
save `file1', replace
restore
merge m:1 narrow_employer using `file1'
drop _merge

preserve 

keep if year==yofl_tech +2

collapse (max) any_tech_ya2= any_tech, by(narrow_employer )
tempfile file1
save `file1', replace
restore
merge m:1 narrow_employer using `file1'

foreach depvar in listseduc wants_at_least_college listsexper exper routine_num functional_num high_sk_tasks_num basic_aa clerk mail routine_accounting light_physical legal accounting_finance sales_cust marketing logistics hr research higher_level_mgmt other_cognitive writing {

	reghdfe `depvar' M_9-P_9 if ypretech==0&(num_narrow_employer_obs>=4)&(years_until_tech==.|(any_tech_ya==1&any_tech_ya2==1)), absorb(czone_year emp_year narrow_employer yearmonth) cluster(narrow_employer)
	coefplot, keep(M_3 M_2 M_1 P_0 P_1 P_2) yline(0) title() ylabel(, angle(0) nogrid valuelabels) vertical xlabel(1 "-3" 2 "-2" 3 "-1" 4 "0" 5 "1" 6 "2" , angle(0) ) graphregion(color(white)) bgcolor(white) scheme(sj) mcolor(black) ciopts(lcolor(black)) omitted graphregion(margin(15 0 0 0)) xtitle("Year Relative to Technology Adoption") xline(3.5,lpattern(dash))

	if "`depvar'"=="listseduc"{
		coefplot, keep(M_3 M_2 M_1 P_0 P_1 P_2) yline(0) title() ylabel(-.03 (.03) .09, angle(0) nogrid valuelabels) vertical xlabel(1 "-3" 2 "-2" 3 "-1" 4 "0" 5 "1" 6 "2" , angle(0) ) graphregion(color(white)) bgcolor(white) scheme(sj) mcolor(black) ciopts(lcolor(black)) omitted graphregion(margin(15 0 0 0)) xtitle("Year Relative to Technology Adoption") xline(3.5,lpattern(dash))
	}
	if "`depvar'"=="wants_at_least_college"{
		coefplot, keep(M_3 M_2 M_1 P_0 P_1 P_2) yline(0) title() ylabel(-.02 (.01) .04, angle(0) nogrid valuelabels) vertical xlabel(1 "-3" 2 "-2" 3 "-1" 4 "0" 5 "1" 6 "2" , angle(0) ) graphregion(color(white)) bgcolor(white) scheme(sj) mcolor(black) ciopts(lcolor(black)) omitted graphregion(margin(15 0 0 0)) xtitle("Year Relative to Technology Adoption") xline(3.5,lpattern(dash))
	}		
	if "`depvar'"=="listsexper"{
		coefplot, keep(M_3 M_2 M_1 P_0 P_1 P_2) yline(0) title() ylabel(-.02 (.02) .08, angle(0) nogrid valuelabels) vertical xlabel(1 "-3" 2 "-2" 3 "-1" 4 "0" 5 "1" 6 "2" , angle(0) ) graphregion(color(white)) bgcolor(white) scheme(sj) mcolor(black) ciopts(lcolor(black)) omitted graphregion(margin(15 0 0 0)) xtitle("Year Relative to Technology Adoption") xline(3.5,lpattern(dash))
	}
	if "`depvar'"=="exper"{
		coefplot, keep(M_3 M_2 M_1 P_0 P_1 P_2) yline(0) title() ylabel(-.07 (.07) .21, angle(0) nogrid valuelabels) vertical xlabel(1 "-3" 2 "-2" 3 "-1" 4 "0" 5 "1" 6 "2" , angle(0) ) graphregion(color(white)) bgcolor(white) scheme(sj) mcolor(black) ciopts(lcolor(black)) omitted graphregion(margin(15 0 0 0)) xtitle("Year Relative to Technology Adoption") xline(3.5,lpattern(dash))
	}
	if "`depvar'"=="routine_num"{
		coefplot, keep(M_3 M_2 M_1 P_0 P_1 P_2) yline(0) title() ylabel(-.2 (.2) 1.2, angle(0) nogrid valuelabels) vertical xlabel(1 "-3" 2 "-2" 3 "-1" 4 "0" 5 "1" 6 "2" , angle(0) ) graphregion(color(white)) bgcolor(white) scheme(sj) mcolor(black) ciopts(lcolor(black)) omitted graphregion(margin(15 0 0 0)) xtitle("Year Relative to Technology Adoption") xline(3.5,lpattern(dash))
	}
	if "`depvar'"=="functional_num"{
		coefplot, keep(M_3 M_2 M_1 P_0 P_1 P_2) yline(0) title() ylabel(-.06 (.06) .18, angle(0) nogrid valuelabels) vertical xlabel(1 "-3" 2 "-2" 3 "-1" 4 "0" 5 "1" 6 "2" , angle(0) ) graphregion(color(white)) bgcolor(white) scheme(sj) mcolor(black) ciopts(lcolor(black)) omitted graphregion(margin(15 0 0 0)) xtitle("Year Relative to Technology Adoption") xline(3.5,lpattern(dash))
	}
	if "`depvar'"=="high_sk_tasks_num"{
		coefplot, keep(M_3 M_2 M_1 P_0 P_1 P_2) yline(0) title() ylabel(-.06 (.06) .18, angle(0) nogrid valuelabels) vertical xlabel(1 "-3" 2 "-2" 3 "-1" 4 "0" 5 "1" 6 "2" , angle(0) ) graphregion(color(white)) bgcolor(white) scheme(sj) mcolor(black) ciopts(lcolor(black)) omitted graphregion(margin(15 0 0 0)) xtitle("Year Relative to Technology Adoption") xline(3.5,lpattern(dash))
	}

	graph export "${root}/output/`depvar'_es.pdf", replace
}
